
/**
 * 
 * Result实体类
 * Result.success 成功
 * Result.faild 失败
 * 
 */
const Result = (function () {
    let instance = null
    function Result() {
        this.state = false
        this.data = null
        this.message = null
        this.code = 200
        this.timestamp = 0
    }
    
    Result.prototype.success = function (data=null, message=null) {
        this.state = true
        this.data = data
        this.message = message
        this.timestamp = Date.now()
        return this
    }
    
    Result.prototype.faild = function(code, message) {
        this.state = false
        this.data = null
        this.code = code
        this.message = message
        this.timestamp = Date.now()
        return this
    }
    
    // export
    return function () {
        if (!instance) {
            instance = new Result()
        }
        return instance
    }
})()

Result.success = function (data, message) {
    return Result().success(data, message)
}

Result.faild = function () {
    return Result().faild(message) 
}



module.exports = {
    Result
}